package top.mh.mybatis.sqlsession;

import top.mh.mybatis.executor.Executor;
import top.mh.mybatis.executor.SimpleExecutor;
import top.mh.mybatis.pojo.Configuration;

/**
 * @author mh
 * @version 1.0
 * @description
 * @since 2024/2/2 16:21
 */
public class DefaultSqlSessionFactory implements SqlSessionFactory {
    private Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }

    /**
     * 打开sql会话：
     * (1) 创建sql执行器
     * (2) 创建sql会话，对于数据库的操作，sqlSession委派执行器去执行CRUD操作
     * @return sqlSession对象
     */
    @Override
    public SqlSession openSession() {
        Executor executor = new SimpleExecutor();
        SqlSession sqlSession = new DefaultSqlSession(configuration, executor);
        return sqlSession;
    }
}
